package com.estore;

import com.estore.network.EStoreServer;
import com.estore.network.EStoreClient;
import com.estore.model.Product;
import com.estore.service.ProductService;

import java.util.List;

/**
 * 测试支付功能修复
 */
public class TestPaymentFix {
    public static void main(String[] args) {
        System.out.println("=== 测试支付功能修复 ===");
        
        // 首先启动服务器（在后台线程中）
        Thread serverThread = new Thread(() -> {
            try {
                EStoreServer server = new EStoreServer();
                server.start();
            } catch (Exception e) {
                System.err.println("服务器启动失败: " + e.getMessage());
            }
        });
        serverThread.setDaemon(true);
        serverThread.start();
        
        // 等待服务器启动
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        
        System.out.println("服务器已启动，开始测试...");
        
        // 测试1: 检查商品库存
        System.out.println("\n--- 测试1: 检查商品库存 ---");
        try {
            ProductService productService = new ProductService();
            List<Product> products = productService.getAllProducts();
            System.out.println("可用商品:");
            for (Product product : products) {
                System.out.printf("- %s (ID: %s): 库存 %d, 价格 ¥%.2f%n", 
                    product.getName(), product.getPrice(), product.getStock(), product.getPrice());
            }
        } catch (Exception e) {
            System.err.println("获取商品列表失败: " + e.getMessage());
        }
        
        System.out.println("\n=== 测试完成 ===");
        System.out.println("请手动启动客户端进行支付测试:");
        System.out.println("1. 运行 EStoreClient");
        System.out.println("2. 登录用户账户");
        System.out.println("3. 添加商品到购物车");
        System.out.println("4. 创建订单并支付");
        System.out.println("5. 观察错误信息是否更清晰");
    }
}